package com.wowangz.cms.topic.poster.service;

import java.util.List;
import java.util.Map;

import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.topic.poster.entity.PosterEntity;

/**
 * @描述：海报的服务层
 * @author HUANGYUAN
 * @TIME:2015年9月22日 上午9:57:41
 */
public class PosterService extends BaseService {
	public String posterSave(PosterEntity poster) throws ServiceException {
		try {
			this.getSqlSession().insert("PosterService.savePoster", poster);
			String id = "" + poster.getId();
			return id;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	public void deletePoster(PosterEntity poster) throws ServiceException{
		try {
			this.getSqlSession().update("PosterService.updatePoster", poster);
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * @描述：修改海报的信息
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午2:16:38
	 * @param poster
	 * @throws ServiceException
	 */
	public void updatePoster(PosterEntity poster) throws ServiceException{
		try {
			this.getSqlSession().update("PosterService.updatePoster", poster);
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * @描述：获得海报的总记录数目
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午2:20:03
	 * @param map
	 * @return
	 */
	public Long findPosterCountByMap(Map<String, Object> map){
		try {
			Object object = this.getSqlSession().selectOne("PosterService.findPosterCountByMap", map);
			return (Long) object;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	/**
	 * @描述：查询最大排序编号
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午3:31:26
	 * @return
	 */
	public Long findMaxSortnumber(){
		try {
			Object object = this.getSqlSession().selectOne("PosterService.findMaxSortnumber");
			return (Long) object;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	public PosterEntity findOnePosterByMap(Map<String, Object> map){
		try {
			Object object = this.getSqlSession().selectOne("PosterService.findOnePosterByMap", map);
			return (PosterEntity) object;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * 获得海报的结果集合
	 * @描述：
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午2:20:26
	 * @param map
	 * @return
	 */
	public List<PosterEntity> findPosterPageByMap(Map<String, Object> map){
		try {
			List<PosterEntity> objects = this.getSqlSession().selectList("PosterService.findPosterPageByMap", map);
			return objects;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	public List<PosterEntity> findAllPosterByMap(Map<String, Object> map){
		try {
			List<PosterEntity> objects = this.getSqlSession().selectList("PosterService.findAllPosterByMap", map);
			return objects;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
}
